package com.flea.hclv.service.impl;

import java.util.List;

import com.flea.hclv.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.flea.hclv.model.dao.HTransferRecordMapper;
import com.flea.hclv.model.entity.HTransferRecord;
import com.flea.hclv.service.HTransferRecordService;
import com.flea.system.utils.FleaStringUtils;

/**
 * @program: project
 * @description: 转账记录
 * @author: shiliqiang
 * @create: 2018-11-02 00:03
 * @version: 1.0
 */
@Service
public class HTransferRecordServiceImpl implements HTransferRecordService {

    @Autowired
    private HTransferRecordMapper hTransferRecordMapper;

    @Override
    public ServerResponse<List<HTransferRecord>> selectByOrderNo(String orderNo) {
        if (orderNo==null){
            return ServerResponse.createByErrorMessage("订单号为空");
        }
        List<HTransferRecord> hTransferRecords = hTransferRecordMapper.selectByOrderNo(orderNo);
        return ServerResponse.createBySuccess(hTransferRecords);
    }

    @Override
    public ServerResponse<String> update(HTransferRecord hTransferRecord, String userId) {
        if (hTransferRecord==null){
            return ServerResponse.createByErrorMessage("参数不能为空");
        }
        int row = hTransferRecordMapper.updateByPrimaryKeySelective(hTransferRecord);
        if (row>0){
            return ServerResponse.createBySuccessMessage("修改成功");
        }
        return ServerResponse.createByErrorMessage("修改失败");
    }

    @Override
    public ServerResponse<String> save(HTransferRecord hTransferRecord, String userId) {
        if (hTransferRecord==null){
            return ServerResponse.createByErrorMessage("参数不能为空");
        }
        hTransferRecord.setId(FleaStringUtils.getGenerateUUID());
        hTransferRecord.setCreateUser(userId);
        hTransferRecord.setModifyUser(userId);
        int row = hTransferRecordMapper.insertSelective(hTransferRecord);
        if (row>0){
            return ServerResponse.createBySuccessMessage("添加成功");
        }
        return ServerResponse.createByErrorMessage("添加失败");
    }
}
